package com.example.easyscript.controller;

import com.example.easyscript.dto.Resp.RunnerInfoReq;
import com.example.easyscript.dto.Resp.RunningTaskInfo;
import com.example.easyscript.service.master.intf.MasterService;
import com.example.easyscript.service.master.intf.TaskManagerService;
import com.example.easyscript.service.master.intf.TaskRunnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(value = "MasterController", tags = "主控")
@Slf4j
@RestController
@RequestMapping(value = "/web/master")
public class MasterController {
    @Resource
    private MasterService masterService;

    @Resource
    private TaskManagerService managerService;

    @Resource
    private TaskRunnerService runnerService;

    @ApiOperation("启动")
    @PostMapping("/start")
    public void startRun() {
        masterService.runMaster();
    }

    @ApiOperation("暂停")
    @PostMapping("/stop")
    public void stopMaster() {
        masterService.stopMaster();
    }

    @ApiOperation("查看TaskManner里面的情况")
    @GetMapping("/getManagerInfo")
    public List<RunningTaskInfo> getManagerInfo() {
        return managerService.getManagerInfo();
    }

    @ApiOperation("查看TaskRunner里面的情况")
    @GetMapping("/getRunnerInfo")
    public RunnerInfoReq getRunnerInfo() {
        return runnerService.getRunnerInfo();
    }

    @ApiOperation("新增运行任务")
    @PostMapping("/addRunnerTask/{taskId}")
    public void addRunnerTask(@PathVariable Integer taskId){
        managerService.addTask(taskId);
    }

    @ApiOperation("新增任务操作")
    @PostMapping("/addRunnerOperation/{taskId}/{operationId}")
    public void addRunnerOperation(@PathVariable Integer taskId, @PathVariable Integer operationId){
        managerService.addRunnerOperation(taskId,operationId);
    }


    @PostMapping("/clean")
    @ApiOperation("清除运行列表")
    public void clean() {
        managerService.cleanAll();
    }
}
